package com.jrsoft.bim.exception;

import com.jrsoft.bim.dto.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.FileNotFoundException;

/**
 * ${DESCRIPTION}
 *
 * @author Blueeyedboy
 * @create 2019-12-20 7:41 PM
 **/
@Slf4j
@ControllerAdvice
public class CustomerExceptionHandler {

	//运行时异常
	@ResponseBody
	@ExceptionHandler(RuntimeException.class)
	public R runtimeExceptionHandler(RuntimeException ex) {
		log.error("RuntimeException:");
		return R.error(ex.getMessage());
	}

	//空指针异常
	@ResponseBody
	@ExceptionHandler(FileNotFoundException.class)
	public R fileNotFoundExceptionHandler(FileNotFoundException ex) {
		log.error("FileNotFoundException:");
		return R.error(ex.getMessage());
	}

	//空指针异常
	@ResponseBody
	@ExceptionHandler(NullPointerException.class)
	public R nullPointerExceptionHandler(NullPointerException ex) {
		log.error("NullPointerException:");
		ex.printStackTrace();
		return R.error(ex.getMessage());
	}

	//空指针异常
	@ResponseBody
	@ExceptionHandler(Exception.class)
	public R exceptionHandler(Exception ex) {
		log.error("Exception:");
		return R.error(ex.getMessage());
	}
}
